package com.info.zhiduoduo.weixin.service;

import com.alibaba.druid.util.StringUtils;
import com.baomidou.mybatisplus.mapper.Condition;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.google.common.collect.Lists;
import com.info.zhiduoduo.common.configs.CommonConfig;
import com.info.zhiduoduo.common.configs.MailConfig;
import com.info.zhiduoduo.common.configs.PayConfig;
import com.info.zhiduoduo.common.configs.ZddUrlConfig;
import com.info.zhiduoduo.common.constants.Constants;
import com.info.zhiduoduo.common.constants.SmartResult;
import com.info.zhiduoduo.common.constants.StatusMsg;
import com.info.zhiduoduo.common.constants.system.UserType;
import com.info.zhiduoduo.common.constants.project.CalcAmountType;
import com.info.zhiduoduo.common.constants.project.ProjectType;
import com.info.zhiduoduo.common.exception.Asserts;
import com.info.zhiduoduo.common.formbean.BaseSimpleFormBean;
import com.info.zhiduoduo.common.utils.DateUtil;
import com.info.zhiduoduo.common.utils.IPUtil;
import com.info.zhiduoduo.common.utils.RandomUtil;
import com.info.zhiduoduo.common.utils.StringUtil;
import com.info.zhiduoduo.core.dto.taxer.TaxerInvoiceServiceChargeDto;
import com.info.zhiduoduo.core.service.*;
import com.info.zhiduoduo.core.service.common.BaseService;
import com.info.zhiduoduo.core.service.common.ContractDocService;
import com.info.zhiduoduo.core.service.common.DocService;
import com.info.zhiduoduo.repository.dto.maker.MakerDetailDto;
import com.info.zhiduoduo.repository.dto.maker.StudioDetailDto;
import com.info.zhiduoduo.repository.dto.taxer.TaxerCompanyDto;
import com.info.zhiduoduo.repository.dto.taxer.TaxerInvoiceDto;
import com.info.zhiduoduo.repository.entity.maker.Maker;
import com.info.zhiduoduo.repository.entity.maker.MakerStudio;
import com.info.zhiduoduo.repository.entity.partner.PartnerBrokerage;
import com.info.zhiduoduo.repository.entity.taxer.TaxerCompany;
import com.info.zhiduoduo.repository.entity.taxer.TaxerInviteCode;
import com.info.zhiduoduo.repository.entity.taxer.TaxerInvoice;
import com.info.zhiduoduo.repository.entity.taxer.TaxerInvoiceProject;
import com.info.zhiduoduo.repository.entity.taxer.TaxerPayment;
import com.info.zhiduoduo.repository.mapper.address.AddressTaxRateMapper;
import com.info.zhiduoduo.repository.mapper.maker.MakerMapper;
import com.info.zhiduoduo.repository.mapper.maker.MakerStudioMapper;
import com.info.zhiduoduo.repository.mapper.taxer.TaxerCompanyMapper;
import com.info.zhiduoduo.repository.mapper.taxer.TaxerInviteCodeMapper;
import com.info.zhiduoduo.repository.mapper.taxer.TaxerInvoiceMapper;
import com.info.zhiduoduo.repository.mapper.taxer.TaxerInvoiceProjectMapper;
import com.info.zhiduoduo.repository.mapper.taxer.TaxerPaymentMapper;
import com.info.zhiduoduo.weixin.formbean.taxer.AddEditInvoiceProjectFormBean;
import com.info.zhiduoduo.weixin.formbean.taxer.ApplyInvoiceFormBean;
import com.info.zhiduoduo.weixin.formbean.taxer.EditTaxerCompanyFormBean;
import com.info.zhiduoduo.weixin.formbean.taxer.EditTaxerInvoiceFormBean;
import com.info.zhiduoduo.weixin.formbean.taxer.InvoiceEmailFormBean;
import com.info.zhiduoduo.weixin.formbean.taxer.InvoiceListFormBean;
import com.info.zhiduoduo.weixin.formbean.taxer.TaxerCompanyListFormBean;
import com.info.zhiduoduo.weixin.formbean.taxer.TaxerSubmitWxpayFormBean;
import com.info.zhiduoduo.weixin.formbean.taxer.WXPayFromBean;

import com.info.zhiduoduo.weixin.pay.WeChatPayService;
import org.apache.commons.io.FilenameUtils;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;
import org.springframework.web.client.RestTemplate;

import java.io.File;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.validation.Valid;
import javax.validation.constraints.Email;
import javax.validation.constraints.Positive;

@Service
public class TaxerService extends BaseService {

    @Autowired
    MakerMapper makerMapper;
    @Autowired
    MakerStudioMapper makerStudioMapper;
    @Autowired
    TaxerCompanyMapper taxerCompanyMapper;
    @Autowired
    TaxerInvoiceMapper taxerInvoiceMapper;
    @Autowired
    TaxerInviteCodeMapper taxerInviteCodeMapper;
    @Autowired
    TaxerPaymentMapper taxerPaymentMapper;
    @Autowired
    TaxerInvoiceProjectMapper taxerInvoiceProjectMapper;
    @Autowired
    AddressTaxRateMapper addressTaxRateMapper;
    @Autowired
    CoreTaxerService coreTaxerService;
    @Autowired
    CoreSensitiveService coreSensitiveService;
    @Autowired
    DocService docService;
    @Autowired
    ContractDocService contractDocService;
    @Autowired
    MailService mailService;
    @Autowired
    CoreBrokerageService coreBrokerageService;
    @Autowired
    CoreProjectService coreProjectService;

    @Autowired
    WeChatPayService weChatPayService;

    @Autowired
    WxMessageService wxMessageService;

    @Autowired
    CommonConfig commonConfig;
    @Autowired
    ZddUrlConfig zddUrlConfig;
    @Autowired
    PayConfig payConfig;
    @Autowired
    MailConfig mailConfig;

    //******************************** 开票申请 ***************************

    public SmartResult applyInvoice(BaseSimpleFormBean<ApplyInvoiceFormBean> formBean) {
        ApplyInvoiceFormBean reqdata = formBean.getReqdata();
        if (reqdata == null) return errorParamSmartResult();
        int userid = formBean.getUserid();
        @Positive BigDecimal amount = reqdata.getAmount();

        MakerDetailDto studio = makerMapper.getUserDetail(userid);
        if (studio == null) return smartResult(StatusMsg.StatusMsg_701);
        if (studio.getState() != 2) return smartResult(StatusMsg.StatusMsg_710);

        //校验敏感词
        String checkResult = coreSensitiveService.checkSensitiveWords(reqdata.getProjectname(), reqdata.getProjectintro());
        Asserts.isBlank(checkResult, StatusMsg.StatusMsg_144);

        //判断账户是否已经到期，如果到期则不能开票
        Date expireDate = studio.getExpireDate();
        if (expireDate == null || DateUtil.getStartOfDay(new Date()).after(expireDate)) {
            return smartResult(StatusMsg.StatusMsg_721);
        }

        // 纯代理/ 用户,判度年度限额
        coreProjectService.checkMakerQuota(0, userid, 0, ProjectType.TAXER, amount, CalcAmountType.PROCESSING);

        int unpayCount = new TaxerPayment().selectCount(Condition.create().eq("userid", userid).eq("state", 1));
        if (unpayCount > 0) {
            return SmartResult.fail(StatusMsg.StatusMsg_723);
        }

        int companyid = reqdata.getCompanyid();
        if (companyid == 0) {

            List<TaxerCompany> companyExit = taxerCompanyMapper.getCompanyExit(formBean.getUserid(), reqdata.getCompanyName(), reqdata.getCreditcode());
            if (CollectionUtils.isEmpty(companyExit)) {
                //新建企业
                TaxerCompany company = new TaxerCompany();
                BeanUtils.copyProperties(reqdata, company);
                company.setUserid(userid);
                company.insert();
                companyid = company.getCompanyid();
            }
        } else {
            // 修改企业
            TaxerCompany company = new TaxerCompany();
            BeanUtils.copyProperties(reqdata, company);
            company.setUserid(userid);
            company.updateById();
            companyid = company.getCompanyid();
        }

        int projectid = reqdata.getProjectid();
        if (projectid == 0) {
            //创建发票项目信息
            TaxerInvoiceProject project = new TaxerInvoiceProject();
            BeanUtils.copyProperties(reqdata, project);
            project.setUserid(userid).setProjectAmount(reqdata.getAmount());
            project.insert();
            projectid = project.getProjectid();
        }

        String applyno = RandomUtil.createRandomNo("INVO_", "");
        TaxerInvoice invoice = new TaxerInvoice();
        invoice.setAmount(amount)
                .setApplyno(applyno)
                .setInvoiceContent(reqdata.getInvoiceContent())
                .setInvoiceType(reqdata.getInvoiceType())
                .setReceiptImg(reqdata.getReceiptImg())
                .setUserid(userid)
                .setUsername(studio.getUsername())
                .setStudioCreditcode(studio.getCreditcode())
                .setStudioPhone(studio.getStudiophone())
                .setStudioAddr(studio.getAddr())
                .setCompanyid(companyid)
                .setCompanyName(reqdata.getCompanyName())
                .setCompanyCreditcode(reqdata.getCreditcode())
                .setCompanyAddr(reqdata.getCompanyAddr())
                .setInvoiceEmail(reqdata.getEmail())
                .setCompanyBank(reqdata.getBankname())
                .setCompanyAcctno(reqdata.getAcctno())
                .setCompanyPhone(reqdata.getCompanyPhone())
                .setProjectid(projectid)
                .setProjectname(reqdata.getProjectname())
                .setCategoryid(reqdata.getCategoryid())
                .setCategoryname(reqdata.getCategoryname())
                .setProjectcycle(reqdata.getProjectcycle())
                .setProjectintro(reqdata.getProjectintro())
               .setDeliveryPath(reqdata.getDeliveryPath())
               .setContactPath(reqdata.getContactPath());

        if (invoice.insert()) {
            // 初始化合伙人分佣记录
            coreBrokerageService.prepareProjectBrokerage(studio.getBindcompid(), userid, invoice.getInvoiceid(), ProjectType.TAXER);
            //创建开票付款记录
            String payno = RandomUtil.createRandomNo("TAX_", "");
            TaxerPayment payment = new TaxerPayment().setType(Constants.TAXER_PAY_TYPE_INVOICE)
                    .setUserid(userid)
                    .setPayno(payno)
                    .setInvoiceid(invoice.getInvoiceid())
                    .setState(1);
            if (payment.insert()) {
                invoice.setPayid(payment.getPayid()).updateById();
                //可以开税户
                if (studio.getTaxAcctState() == Constants.STUDIO_TAX_ACCT_NOT_QUALIFIED) {
                    new MakerStudio().setUserid(userid)
                            .setTaxAcctState(Constants.STUDIO_TAX_ACCT_QUALIFIED)
                            .setOpenTaxAcctStarttime(new Date())
                            .updateById();
                }
            }
            // 创客申请开票通知Phoenix
            wxMessageService.invoiceApplyNotifyKefu(invoice);

            return smartResult(invoice.getInvoiceid());
        }

        return optFailSmartResult();
    }

    /**
     * 根据userid得到地区id和状态查询年度税率或者季度费率,计算应该要交的税费
     *
     * @return
     */
    public SmartResult<TaxerInvoiceServiceChargeDto> getInvoiceServiceChargeV2(BaseSimpleFormBean<Integer> formBean) {
        if (null == formBean || null == formBean.getReqdata()) {
            return errorParamSmartResult();
        }
        TaxerInvoiceServiceChargeDto chargeDto = coreTaxerService.calcInvoiceServiceChargeV2(formBean.getReqdata());
        return SmartResult.success(chargeDto);
    }

    public SmartResult<TaxerCompanyDto> getCompanyList(BaseSimpleFormBean<TaxerCompanyListFormBean> formBean) {
        TaxerCompanyListFormBean reqdata = formBean.getReqdata();
        if (reqdata == null) return errorParamSmartResult();

        String name = reqdata.getName();
        int taxerid = reqdata.getUserid();

        List<TaxerCompanyDto> companyList = taxerCompanyMapper.getCompanyList(name, taxerid);
        return smartResult(companyList);
    }

    @Deprecated
    public SmartResult<TaxerInvoiceServiceChargeDto> getInvoiceServiceCharge(BaseSimpleFormBean<Integer> formBean) {
        Integer invoiceid = formBean.getReqdata();

        TaxerInvoiceServiceChargeDto taxerInvoiceServiceChargeDto = coreTaxerService.calcInoiceServiceCharge(invoiceid);
        return smartResult(taxerInvoiceServiceChargeDto);
    }

    public SmartResult<TaxerInvoiceDto> getInvoiceList(BaseSimpleFormBean<InvoiceListFormBean> formBean) {
        int userid = formBean.getUserid();
        InvoiceListFormBean reqdata = formBean.getReqdata();
        if (reqdata == null) return errorParamSmartResult();

        String name = reqdata.getName();
        int state = reqdata.getState();
        Date startDate = reqdata.getStartDate();
        Date endDate = reqdata.getEndDate();

        if (startDate == null) startDate = new Date(0);
        if (endDate == null) endDate = new Date();

        StudioDetailDto studio = makerStudioMapper.getStudioDetail(userid);
        if (studio == null) return smartResult(StatusMsg.StatusMsg_701);
        if (studio.getState() != 2) return smartResult(StatusMsg.StatusMsg_710);

        int realState = state == 3 ? 2 : 1;
        int paidState = state >= 2 ? 2 : 1;
        Page<TaxerInvoiceDto> page = PageHelper.startPage(formBean.getPage(), formBean.getRows());
        taxerInvoiceMapper.getInvoiceList(userid, name, paidState, realState, 0, startDate, endDate, "");
        return smartResultPage(page);
    }

    public SmartResult getInvoiceDetail(BaseSimpleFormBean<Integer> formBean) {
        Integer invoiceid = formBean.getReqdata();
        TaxerInvoice taxerInvoice = new TaxerInvoice().selectById(invoiceid);
        if (taxerInvoice.getCompanyid() != null) {
            // 获取 企业 的联系人 和 联系电话
            TaxerCompany taxerCompany = new TaxerCompany().selectById(taxerInvoice.getCompanyid());
            if (taxerCompany != null) {
                if (!StringUtils.isEmpty(taxerCompany.getContactPerson())) {
                    taxerInvoice.setContactPerson(taxerCompany.getContactPerson());
                }
                if (!StringUtils.isEmpty(taxerCompany.getContactPhone())) {
                    taxerInvoice.setContactPhone(taxerCompany.getContactPhone());
                }
            }
        }
        return smartResult(taxerInvoice);
    }

    public SmartResult editInovice(BaseSimpleFormBean<EditTaxerInvoiceFormBean> formBean) {
        EditTaxerInvoiceFormBean reqdata = formBean.getReqdata();
        if (reqdata == null) return errorParamSmartResult();
        BigDecimal amount = reqdata.getAmount();
        TaxerInvoice invoice = new TaxerInvoice().selectById(reqdata.getInvoiceid());
        if (invoice == null || invoice.getState() == 2) return smartResult(StatusMsg.StatusMsg_715);

        //校验敏感词
        String checkResult = coreSensitiveService.checkSensitiveWords(invoice.getProjectname(), invoice.getProjectintro());
        Asserts.isBlank(checkResult, StatusMsg.StatusMsg_144);

        // 纯代理/ 用户,判度年度限额
        Integer userid = invoice.getUserid();
        BigDecimal yearlyTotalAmount = coreProjectService.getUserYearlyTotalAmount(userid, CalcAmountType.CHECKED);
        if (yearlyTotalAmount.add(amount).doubleValue() > commonConfig.getTaxerYearlyQuota()) {
            return smartResult(StatusMsg.StatusMsg_720).setObject(yearlyTotalAmount);
        }

        BeanUtils.copyProperties(reqdata, invoice);
        if (!invoice.updateById()) {
            smartResult(StatusMsg.StatusMsg_199);
        }

        if (reqdata.getCompanyid() != null) {
            TaxerCompany company = new TaxerCompany().selectById(reqdata.getCompanyid());
            if (company != null) {
                company.setContactPerson(reqdata.getContactPerson()).setContactPhone(reqdata.getContactPhone());
                if (!company.updateById()) {
                    smartResult(StatusMsg.StatusMsg_199);
                }
            }
        }
        return smartResult();
    }

    public SmartResult editCompany(BaseSimpleFormBean<EditTaxerCompanyFormBean> formBean) {
        EditTaxerCompanyFormBean reqdata = formBean.getReqdata();
        if (reqdata == null) return errorParamSmartResult();

        int taxerid = formBean.getUserid();
        TaxerCompany company = new TaxerCompany().setUserid(taxerid);
        BeanUtils.copyProperties(reqdata, company);
        if (0 == reqdata.getCompanyid()) {
            if (!company.insert()) {
                return optFailSmartResult();
            }
            return smartResult(company.getCompanyid());
        } else {
            if (company.updateById()) return smartResult(company.getCompanyid());
        }
        return optFailSmartResult();
    }

    public SmartResult delCompany(BaseSimpleFormBean<Integer> formBean) {
        Integer companyid = formBean.getReqdata();

        if (new TaxerCompany().deleteById(companyid)) return smartResult();
        return optFailSmartResult();
    }

    public SmartResult<TaxerCompanyDto> getTaxerCompanyInfo(BaseSimpleFormBean<Integer> formBean) {
        Integer companyid = formBean.getReqdata();
        TaxerCompanyDto companyInfo = taxerCompanyMapper.getCompanyInfo(companyid);
        if (companyInfo != null) return smartResult(companyInfo);
        return smartResult(StatusMsg.StatusMsg_717);
    }

    public SmartResult delInvoice(BaseSimpleFormBean<Integer> formBean) {
        Integer invoiceid = formBean.getReqdata();
        TaxerInvoiceDto invoice = taxerInvoiceMapper.getInvoice(invoiceid);

        if (invoice == null) return smartResult(StatusMsg.StatusMsg_714);
        if (invoice.getUserid() != formBean.getUserid()) return optFailSmartResult();

        //删除佣金记录
        new PartnerBrokerage().delete(Condition.create().eq("projectid", invoice.getInvoiceid()));
        new TaxerInvoice().deleteById(invoiceid);
        new TaxerPayment().deleteById(invoice.getPayid());
        return smartResult();
    }

    public void generateInviteCode() {
        for (int i = 0; i < 100; i++) {
            String inviteCode = RandomUtil.generateLetterString(4).toLowerCase();
            while (taxerInviteCodeMapper.selectByCode(inviteCode) != null) {
                inviteCode = RandomUtil.generateLetterString(4).toLowerCase();
            }
            new TaxerInviteCode().setInviteCode(inviteCode).setAmount(BigDecimal.valueOf(5000)).insert();
        }
    }

    public SmartResult submitPay(BaseSimpleFormBean<TaxerSubmitWxpayFormBean> formBean, HttpServletRequest request) {

        int idtype = formBean.getIdtype();
        int userid = formBean.getUserid();

        TaxerSubmitWxpayFormBean reqdata = formBean.getReqdata();
        if (reqdata == null) return errorParamSmartResult();

        int type = reqdata.getType();
        Maker maker = new Maker().selectById(userid);
        if (maker == null) return smartResult(StatusMsg.StatusMsg_201);

        String openid = "";
        int orderType = 0;
        if (idtype == UserType.MAKER) {
            openid = maker.getOpenid();
            orderType = 2;
        } else if (idtype == UserType.TAXER) {
            openid = maker.getTaxerOpenid();
            orderType = 1;
        } else {
            return errorParamSmartResult();
        }

        if (StringUtil.isEmpty(openid)) {
            return errorParamSmartResult();
        }

        TaxerPayment payment = null;
        String orderDesc = "";
        if (type == Constants.TAXER_PAY_TYPE_VERIFY || type == Constants.TAXER_PAY_TYPE_RENEW) {
            payment = taxerPaymentMapper.findRegisterPayment(userid, type);
            orderDesc = "开户服务费";
        } else if (type == Constants.TAXER_PAY_TYPE_INVOICE) {
            //重新再次计算税费，防止在点击支付按钮前临时又变了。

            int invoiceid = reqdata.getInvoiceid();
            TaxerInvoice invoice = new TaxerInvoice().selectById(invoiceid);
            Asserts.notNull(invoice, StatusMsg.StatusMsg_714);
            // 纯代理/ 用户,判度创客限额
            coreProjectService.checkMakerQuota(0, invoice.getUserid(), 0, ProjectType.TAXER, invoice.getAmount(), CalcAmountType.CHECKED);

            coreTaxerService.calcInvoiceServiceChargeV2(invoiceid);
            payment = taxerPaymentMapper.findInvoicePayment(userid, invoiceid);
            orderDesc = "开票服务费";
        }

        if (payment == null) return smartResult(StatusMsg.StatusMsg_712);

        //支付以分为单位
        int orderPrice = payment.getAmount().multiply(BigDecimal.valueOf(100)).intValue();
        // int orderPrice = 1;
        WXPayFromBean wxPayFromBean = new WXPayFromBean().setOpenid(openid)
                .setOrderNo(payment.getPayno())
                .setOrderPrice(orderPrice)
                .setOrderDesc(orderDesc)
                .setOrderType(orderType);
        RestTemplate rest = new RestTemplate();
        return weChatPayService.weChatPay(wxPayFromBean, IPUtil.getIpAddr(request));
    }

    public SmartResult getInvoiceProjectList(BaseSimpleFormBean<String> formBean) {
        String reqdata = formBean.getReqdata();
        int userid = formBean.getUserid();

        Page<Object> page = PageHelper.startPage(formBean.getPage(), formBean.getRows());
        taxerInvoiceProjectMapper.getProjectList(userid, reqdata);
        return smartResultPage(page);
    }

    public SmartResult addEditInvoiceProject(BaseSimpleFormBean<AddEditInvoiceProjectFormBean> formBean) {
        AddEditInvoiceProjectFormBean reqdata = formBean.getReqdata();

        if (reqdata == null) return errorParamSmartResult();

        TaxerInvoiceProject project = new TaxerInvoiceProject();
        BeanUtils.copyProperties(reqdata, project);

        if (reqdata.getProjectid() == 0) {
            project.setProjectid(null);
        }

        project.insertOrUpdate();
        return smartResult(project.getProjectid());
    }

    public SmartResult delInvoiceProject(BaseSimpleFormBean<Integer> formBean) {
        Integer projectid = formBean.getReqdata();

        boolean delete = new TaxerInvoiceProject().deleteById(projectid);
        if (delete) return smartResult();
        return optFailSmartResult();
    }

    public SmartResult sendContractEmail(BaseSimpleFormBean<InvoiceEmailFormBean> formBean) {
        InvoiceEmailFormBean reqdata = formBean.getReqdata();
        int invoiceid = reqdata.getInvoiceid();
        @Email String email = reqdata.getEmail();

        TaxerInvoiceDto invoice = taxerInvoiceMapper.getInvoice(invoiceid);

        File file = docService.getOrCreateContractFile(invoice, null);
        if (file == null) return optFailSmartResult();

        String subject = "项目合同-" + FilenameUtils.getBaseName(file.getName());
        String date = DateUtil.getString(invoice.getCreatetime(), DateUtil.FORMAT_STYLE_3);
        String content = String.format(mailConfig.getContractMailContent(), date, invoice.getCompanyName(), invoice.getUsername());

        ArrayList<String> toList = Lists.newArrayList(email);
        ArrayList<String> attachments = Lists.newArrayList(file.getAbsolutePath());

        boolean sent = mailService.sendMailWithAttachments(toList, subject, content, attachments);
        if (sent) return smartResult();
        return optFailSmartResult();
    }

    public SmartResult sendPdfContractEmail(BaseSimpleFormBean<InvoiceEmailFormBean> formBean) {
        InvoiceEmailFormBean reqdata = formBean.getReqdata();
        int invoiceid = reqdata.getInvoiceid();
        @Email String email = reqdata.getEmail();

        TaxerInvoiceDto invoice = taxerInvoiceMapper.getInvoice(invoiceid);

        File file = contractDocService.generateInvoiceContractPdfFile(invoice.getInvoiceid());
        if (file == null) return optFailSmartResult();

        String subject = "项目合同-" + FilenameUtils.getBaseName(file.getName());
        String date = DateUtil.getString(invoice.getCreatetime(), DateUtil.FORMAT_STYLE_3);
        String content = String.format(mailConfig.getContractMailContent(), date, invoice.getCompanyName(), invoice.getUsername());

        ArrayList<String> toList = Lists.newArrayList(email);
        ArrayList<String> attachments = Lists.newArrayList(file.getAbsolutePath());

        boolean sent = mailService.sendMailWithAttachments(toList, subject, content, attachments);
        if (sent) return smartResult();
        return optFailSmartResult();
    }

    public SmartResult getTaxerInviteCodeList(BaseSimpleFormBean<String> formBean) {
        @Valid String name = formBean.getReqdata();
        Page<Object> page = PageHelper.startPage(formBean.getPage(), formBean.getRows());
        taxerInviteCodeMapper.selectListByName(name);
        return smartResultPage(page);
    }
}
